package com.globallogic.model.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

import com.globallogic.model.Activity;
import com.globallogic.model.transferobject.DailyPlanTo;

@Entity
@Table(name = "DailyPlan")
public class DailyPlan implements EntityInterface <DailyPlanTo> {

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public Activity getActivity() {
		return activity;
	}

	public void setActivity(Activity activity) {
		this.activity = activity;
	}

	public int getEstimateDuration() {
		return estimateDuration;
	}

	public void setEstimateDuration(int estimateDuration) {
		this.estimateDuration = estimateDuration;
	}

	public int getActualDuration() {
		return actualDuration;
	}

	public void setActualDuration(int actualDuration) {
		this.actualDuration = actualDuration;
	}

	public String getComments() {
		return comments;
	}

	public void setComments(String comments) {
		this.comments = comments;
	}

	public int getId() {
		return this.id;
	}

	public void setId(int id) {
        this.id = id;
	}
    
	public void setUsername(String username) {
		this.username = username;
	}
	
	public String getUsername() {
		return username;
	}
	
	@Override
	public boolean equals(Object obj) {

		if (!(obj instanceof DailyPlan)) {
			return false;
		}

		DailyPlan dailyPlan = (DailyPlan) obj;

		if (!this.activity.equals(dailyPlan.activity)) {
			return false;
		}

		if (this.actualDuration != dailyPlan.actualDuration) {
			return false;
		}

		if (this.estimateDuration != dailyPlan.estimateDuration) {
			return false;
		}

		if (!this.comments.equals(dailyPlan.getComments())) {
			return false;
		}

		if (this.date.compareTo(dailyPlan.getDate()) != 0) {
			return false;
		}

		return true;

	};

	@Column(name = "date")
	private Date date;
	@Column(name = "activity")
	private Activity activity;
	@Column(name = "estimateDuration")
	private int estimateDuration;
	@Column(name = "actualDuration")
	private int actualDuration;
	@Column(name = "comments")
	private String comments;
	@Column(name = "username")
	private String username;

	
	@Id
	@GeneratedValue
	private int id;

	@Override
	public Object getPrimaryKey() {
		return id;
	}

	@Override
	public DailyPlanTo getTo() {
		DailyPlanTo dailyPlanTo = new DailyPlanTo(); 
		
		dailyPlanTo.activity = activity;
		dailyPlanTo.actualDuration = actualDuration;
		dailyPlanTo.estimateDuration = estimateDuration;
		dailyPlanTo.comments = comments;
		dailyPlanTo.date = date;
		dailyPlanTo.id = id;
		dailyPlanTo.username = username; 

		return dailyPlanTo;
	}

	@Override
	public String toString() {
		return "activity: " + activity +
			   "  actualDuration: " + actualDuration +
			   "  estimateDuration: " + estimateDuration +
			   "  comments: " + comments;
	}
}
